package jdbc1;

import java.sql.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class SelectSTu {
    public static void main(String[] args) {
    //错误
        try {
            //static{}执行了
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return;
        }
        String sql="select * from s_student order by stuno desc";
        String url = "jdbc:mysql://localhost:3308/java83?useUnicode=true&characterEncoding=utf8&useSSL=false" +
                "&serverTimezone=Asia/Shanghai";
        try {
            Connection con = DriverManager.getConnection(url, "xukang", "Xu1234");

            PreparedStatement ps = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);

            ResultSet rs = ps.executeQuery();
            for (int i = 0; i < 10&&rs.next(); i++) {
                long stuno = rs.getLong("stuno");
                String sname = rs.getString("sname");
                System.out.println(i+":"+stuno+","+sname);
            }
            rs.previous();
            rs.previous();
            rs.previous();
            System.out.println("第七个：");
            long stuno = rs.getLong("stuno");
            String sname = rs.getString("sname");
            System.out.println(stuno+","+sname);
            rs.close();
            ps.close();
            con.close();//？
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
